package com.clouddot.baipai.ui.Dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.constraint.ConstraintLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.clouddot.baipai.R;
import com.clouddot.baipai.infrastructure.environment.Env;


/**
 * Created by wxy on 2018/4/2.
 */

public class V_updateDailog {
    private Dialog Dialog;
    private ConstraintLayout constraintLayout;
    private Context context;
    private Button calce, sure;
    private View view;
    private TextView textView;

    public V_updateDailog(Context context) {
        this.context = context;
        initView();

    }

    public Button[] getBtnView() {
        Button[] buttons = new Button[2];
        sure = constraintLayout.findViewById(R.id.btn_download);
        calce = constraintLayout.findViewById(R.id.btn_cancle);
        buttons[0] = sure;
        buttons[1] = calce;
        return buttons;
    }

    public TextView getTextView() {
        return textView;
    }

    private void initView() {
        constraintLayout = (ConstraintLayout) LayoutInflater.from(context).inflate(R.layout.v_dialog_update, null);
        textView = constraintLayout.findViewById(R.id.content);
    }

    public void showDialog() {

        Dialog = getDialog();
        Dialog.show();

    }

    public void closeDialog() {
        if (Dialog != null) {
            Dialog.dismiss();
        }
    }

    public Dialog getDialog() {
        if (Dialog == null) {
            Dialog = new Dialog(context, R.style.ActionDialogStyle);
        }

        Dialog.setContentView(constraintLayout);

        Window dialogWindow = Dialog.getWindow();

        view = dialogWindow.getDecorView();
        lock();

        view.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int i) {
                lock();
            }
        });

        WindowManager.LayoutParams lp = dialogWindow.getAttributes();

        lp.width = WindowManager.LayoutParams.MATCH_PARENT;

        lp.height = 900;

        dialogWindow.setAttributes(lp);

        Dialog.setCancelable(false);

        return Dialog;
    }

    private void lock() {
        int uiFlags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE;
        view.setSystemUiVisibility(uiFlags);
    }


}



